<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>

<script>
    const obj = {
        uname: "ljw",
        age: 18
    }

    // 解构语法
    // 要求属性名和对象名必须一致
    const {uname, age} = obj
    console.log(uname, age)


    // 对象解构的变量名 可以重新命名  对象中的变量名：解构的新变量名

    const {uname: myname, age: myage} = obj

    console.log(myname, myage)

    // 解构数组对象
    const pig = [
        {
            uname: '佩奇',
            age: 6
        }
    ]

    const [{uname: pname, age: page}] = pig
    console.log(pname, page)

    // 多级对象解构
    const pfamily = {
        name: "佩奇",
        family: {
            mother: "猪妈妈",
            father: "猪爸爸",
            brother: "乔治"
        }
    }

    const {name: ppn, family: {mother, father, brother}} = pfamily
    console.log(ppn, mother, father, brother)
</script>
    
</body>
</html>